﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AutoCooker5
{
    /// <summary>
    /// 到这里，我们几乎得到我们想要的效果了。
    /// 更加苛刻的情况是这样的，Mother和Son有自己的事情要做，也就是说，委托调用的时间比较长，
    /// 那么在调用委托方法的时候，AutoCooker要什么也不能做，在那里等待么？
    /// 
    /// 解决方案：异步委托轮询
    ///             (see AutoCooker6)
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            AutoCooker5 easyCooker = new AutoCooker5();
            Stopwatch stopwatchClock = new Stopwatch();

            easyCooker.started += new CookStartedReply(Mother.CookStartedReply);
            easyCooker.completed += new CookCompletedReply(Mother.CookCompletedReply);
            easyCooker.completed += new CookCompletedReply(Son.CookCompletedReply);
            
            stopwatchClock.Start();
            easyCooker.DoCook();
            stopwatchClock.Stop();
            // 输出大于12秒，因为有循环和GetInvocationList()的调用，所以用时大于12秒：
            Console.Write("DoCook() take {0} seconds, is it really the case? lots of time consumed by listeners is calculated in it!", stopwatchClock.Elapsed.TotalSeconds); 
            

            Console.ReadLine();
        }
    }
}
